﻿using System.Collections.Generic;

namespace AirportApp.Data
{
    public class AirportsByName : List<AirportsInGroup>
    {
        private static readonly string Groups = "#abcdefghijklmnopqrstuvwxyz";

        private Dictionary<string, AirportsInGroup> groups = new Dictionary<string, AirportsInGroup>();

        public AirportsByName(AirportItem[] allAirports)
        {
            if (allAirports == null)
            {
                return;
            }
            List<AirportItem> airport = new List<AirportItem>(allAirports);
            //people.Sort(Person.CompareByFirstName);

            Dictionary<string, AirportsInGroup> groups = new Dictionary<string, AirportsInGroup>();

            foreach (char c in Groups)
            {
                AirportsInGroup group = new AirportsInGroup(c.ToString());
                this.Add(group);
                groups[c.ToString()] = group;
            }

            foreach (AirportItem a in allAirports)
            {
                string key = a.Key.ToString();
                key = key.ToLower();
                if (Groups.IndexOf(key) < 0)
                {
                    key = "#";
                }

                groups[key].Add(a);
            }
        }
    }
}
